﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UMLDesigner
{
    static class WindowsManager
    {
        private static MainWindow mainWindow;
        private static FormControl formControl;

        private static List<RelationView> relations = new List<RelationView>();
        private static List<ClassView> classes = new List<ClassView>();

        private static ClassView selectedClass = null;
        private static RelationView relationToCreate = null;
        
        public static Form Build() {
            mainWindow = new MainWindow();
            formControl = mainWindow.GetControlFormulario();

            return mainWindow;
        }

        public static List<RelationView> GetRelations()
        {
            return relations;
        }

        public static void AddRelations(RelationView rel, ClassView iniClass, ClassView endClass)
        {
            rel.SetIniClass(iniClass);
            rel.SetEndClass(endClass);
            relations.Add(rel);
            //Pintamos todas las relaciones
            mainWindow.PaintRelations();
        }

        public static void FormRefresh(ClassView classView) {
            formControl.Refresh(classView);
        }

        public static void SelectClass(ClassView classView)
        {
            if (relationToCreate != null && selectedClass!=null)
            {
                AddRelations(relationToCreate, selectedClass, classView);
                relationToCreate = null;
            }

            DeselectClass();
            selectedClass = classView;
            selectedClass.Select();

            FormRefresh(classView);
        }

        public static void DeselectClass()
        {
            if (selectedClass != null)
            {
                selectedClass.Deselect();
                formControl.Deselect();
                selectedClass = null;
            }
        }

        public static void SetRelationToCreate(RelationView rel)
        {
            relationToCreate = rel;
        }

        public static void AddClass(ClassView clase)
        {
            classes.Add(clase);
        }
        public static void AddAttributeToForm(string name, string type, string visibility)
        {
            formControl.AddAttribute(name, type, visibility);
         
        }
        public static void ModifyAttribute(string name, string type, string visibility)
        {
            formControl.ModifyAttribute(name, type, visibility);
        }       
    }
}
